package 滑动窗口;

import java.util.HashSet;
import java.util.Set;

/**
 * @author tmh
 * @date 2025/3/7 16:48
 * @description
 */
public class T03无重复字符的最长子串 {
    public int lengthOfLongestSubstring(String s) {
        Set<Character> set = new HashSet<>();
        int left = 0,right = 0;
        int maxLen =0;
        for (int i=0;i<s.length();i++){
            while (set.contains(s.charAt(i))){
                set.remove(s.charAt(left));
                left++;
            }
            set.add(s.charAt(i));
            int len = right-left+1;
            maxLen=Math.max(len,maxLen);
            right++;
        }
        return maxLen;
    }
}
